<?php

/*
  VoIP Wholesale 1.0
  ------------------
  Document   : module_origin_edit
  Created on : Nov 29, 2011, 4:29:10 PM
  Author     : Milos Jovanovic <miloscode@gmail.com>
  Description:

 */
?>
<div id="page-title"><?=$trunk['short_name']?></div>

<div id="page-desc"><?=lang('text_origin_trunks_routing_desc')?></div>

<div class="ui-widget"> 
    <div id="content">
        <fieldset>
        <!-- PAGE CONTENT -->
	<form action="" method="post" id="route-trunk" onsubmit="return false;"> 
		<fieldset class="ui-widget-content ui-corner-all">
		<legend class="ui-widget-content ui-corner-all"><?=lang('text_trunk_information')?></legend>
				<p>
					<label><?=lang('term_carrier')?></label> 
					<?php 
					$carrier = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($trunk['carrier_id']); 					
					?>
					<input type="text" value="<?=$carrier['username']?>" class="text ui-state-disabled ui-widget-content ui-corner-all deactivated"/>
                </p>
				<p>
					<label><?=lang('term_short_name')?></label> 
					<input type="text" name="data[short_name]" id="short_name" value="<?=$trunk['short_name']?>" class="deactivated text ui-state-disabled text ui-widget-content ui-corner-all" /> 					
                </p>
			</fieldset>
		<fieldset class="ui-widget-content ui-corner-all">
		<legend class="ui-widget-content ui-corner-all"><?=lang('text_routing_family')?></legend>			
				<p>
					<select name="data[family_id]" id="family">
						<?php if(!isset($linked_family_id) || $linked_family_id =="0"){?>
						<option value="none"><?=lang('text_choose_family')?></option>
						<?php }?>
						<?php
							foreach($families as $family)
							{ ?>
								<option value="<?=$family['id']?>" <?php if($linked_family_id == $family['id']){?>selected="selected"<?php }?>><?=$family['short_name']?></option>
							<?php }
						?>
					</select>
                </p>	
				<div class="family_trunks">
					<?php	
						$text = "";
						foreach($linked_family_trunks as $family_trunk)
						{	
							if($family_trunk['allowed'] == "1")
							{
								$allowed = " checked='checked'";
								$disallowed = "";
							}
							else
							{
								$allowed = "";
								$disallowed = " checked='checked'";
							}
							$car = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($family_trunk['carrier_id']);
							$text .= "<div class='row'><span class='virtual-links' rel='".$family_trunk['id']."'>".$car['username']." - ".$family_trunk['short_name']."</span>&nbsp;&nbsp;&nbsp;";
							$text .= "<span class='radio'><input type='radio' name='data[family_trunks][".$family_trunk['id']."]' value='0' ".$disallowed."/><label>".lang('text_disallowed')."</label></span>";			
							$text .= "<span class='radio'><input type='radio' name='data[family_trunks][".$family_trunk['id']."]' value='1' ".$allowed." /><label>".lang('text_allowed')."</label></span>";			
							$text .= "<a class='open-event' href='javascript:void(0);' title='".$this->MODULE->module_trunks->show_status_desc($family_trunk['id'],"termination")."'>".$this->MODULE->module_trunks->show_status_msg($family_trunk['id'],"termination")."</a>"."&nbsp;&nbsp;&nbsp;";
							$text .= "</div>";
						}
						print $text;
					?>
				</div>
		</fieldset>
		<fieldset class="ui-widget-content ui-corner-all">
		<legend class="ui-widget-content ui-corner-all"><?=lang('text_extra_trunks')?></legend>			
			<br />
			<script>
				var linked_trunks = <?=count($linked_trunks)?>;
			</script>			
			<div id="trunks">
				<?php
				if(count($linked_trunks) > 0)
				{
					$text = "";
					foreach($linked_trunks as $termination_trunk_id => $short_name)
					{
						$tru = $this->PACKAGE->routing->trunks->get_trunk_as_array_by_id($termination_trunk_id,'termination');
						$car = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($tru['carrier_id']);
						$text .= "<div class='row'><input type='hidden' name='data[trunks][]' value='".$termination_trunk_id."' /><span class='virtual-links' rel='".$termination_trunk_id."'>".$car['username']." - ".$short_name."</span>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='show_unlink_trunk_dialog(this, \"".$termination_trunk_id."\", \"".$trunk['id']."\")'>".lang('term_delete')."</a>";
						$text .= "<a class='open-event' href='javascript:void(0);' title='".$this->MODULE->module_trunks->show_status_desc($termination_trunk_id,"termination")."'>".$this->MODULE->module_trunks->show_status_msg($termination_trunk_id,"termination")."</a>"."&nbsp;&nbsp;&nbsp;";
						$text .= "</div>";
						print $text;
						$text = "";
					}
					print "<hr />";
				}
				else
				{
					print lang('term_no_trunks_linked');
				}
				?>
			</div>
		
			<br />
			<a href="javascript:void(0);" id="link-trunks-button" class="button ui-state-default ui-corner-all" title="<?=lang('term_add_trunk')?>"><span class="ui-icon ui-icon-circle-plus"></span><text><?=lang('term_link_trunks')?></text></a>
		
		</fieldset>		
		
				<p>
					<input type="hidden" name="data[origin_trunk_id]" value="<?=$trunk['id']?>"/>				
					<input type="hidden" name="data[confirm]" id="confirm" value="false"/>
					<script type="text/javascript">
						var trunk_ID = "<?=$trunk['id']?>";
					</script>					
					<div id="response"></div><br />
					<button id="module-route-origin-trunk"><?=lang('button_save')?></button>&nbsp;
					<button id="module-route-cancel"><?=lang('button_cancel')?></button>
				</p>
	 </form> 

	 </div>    
</div>   

						<div id="link-trunk">
							<p>			
								<form action="javascript: void(0);" id="modal-form" method="post">
								<?php foreach($trunks as $trunk){
								$car = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($trunk['carrier_id']);
								?>
								 <div class="field-parent <?php if(isset($linked_trunks[$trunk['id']])){?>hidden-trunk<?php }?>" id="field_<?=$trunk['id']?>">
									<div class="label"><input type="checkbox" class="checkboxes" name="trunks[<?=$trunk['id']?>]" value="<?=$trunk['short_name']?>"/></div>
									<div class="text"><span class='virtual-links' rel='<?=$trunk['id']?>'><?=$car['username']?> - <?=$trunk['short_name']?></span>&nbsp;&nbsp;&nbsp;<a class="open-event" href="javascript:void(0);" title="<?=$this->MODULE->module_trunks->show_status_desc($trunk['id'],"termination")?>"><?=$this->MODULE->module_trunks->show_status_msg($trunk['id'],"termination")?></a></div><br />
								 </div>
								<?php }?>
								</form>
							</p>
						</div>	
						
						<div id="unlink-trunk" title="<?=lang('term_confirm_action')?>">
							<p>	
								<?=lang('text_this_trunk_has_previously_been_linked_with_this_origin_trunk')?><br />
								<?=lang('text_if_you_confirm_the_trunk_will_be_unlinked_from_origin_trunk')?><br /><br />
								<?=lang('text_if_you_click_yes_deletion_doesnt_start_instantly')?>								
							</p>
						</div>
